package com.example.demo.service;

import ch.qos.logback.core.db.dialect.DBUtil;
import com.example.demo.mapper.ItemsMapper;
import com.example.demo.mapper.UserMapper;
import com.example.demo.pojo.dbItems;
import com.example.demo.pojo.dbRole;
import com.example.demo.pojo.dbUser;
import com.example.demo.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ItemsServiceImpl implements ItemsService {
    @Autowired
    ItemsMapper itemsMapper;
    @Autowired
    UserMapper userMapper;

    @Override
    public Result selectAll() {
        List<dbItems> list=itemsMapper.selectAll();
        if (list!=null)
            return Result.success(list);
        return Result.fail("查询失败");
    }

    @Override
    public Result selectItemById(Integer id) {
        dbItems item=itemsMapper.selectItemById(id);
        if (item!=null)
            return Result.success(item);
        return Result.fail("错误");
    }

    @Override
    public Result add(dbItems item) {
        Integer i=itemsMapper.add(item);
        if (i==1)
            return Result.success();
        return Result.fail();
    }

    @Override
    public Result update(dbItems items) {
        itemsMapper.update(items);
        return Result.success();
    }

    @Override
    public Result delete(Integer id) {
        Integer i=itemsMapper.delete(id);
        if (i==1){
            return Result.success();
        }
        return Result.fail();
    }

    @Override
    public Result selectByRole(dbRole dbRole) {
        System.out.println(dbRole);
        List<dbItems> list=itemsMapper.selectByRole(dbRole);
        return Result.success(list);
    }

}
